Add a new API call gtk_icon_theme_list_contexts so that one can choose
authorRodney Dawes <dobey@novell.com>
Wed, 21 Mar 2007 19:31:01 +0000 (19:31 +0000)
committerRodney Dawes <dobey@src.gnome.org>
Wed, 21 Mar 2007 19:31:01 +0000 (19:31 +0000)
2007-03-21  Rodney Dawes  <dobey@novell.com>

* gtk/gtk.symbols:
* gtk/gtkicontheme.[ch]:
* docs/reference/gtk/gtk-sections.txt:
* tests/testicontheme.c:
Add a new API call gtk_icon_theme_list_contexts so that one can
choose icons from a theme by context (#420719)

svn path=/trunk/; revision=17550

ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/gtk.symbols
gtk/gtkicontheme.c
gtk/gtkicontheme.h
tests/testicontheme.c

index 0e3d298ea90ebbb3bdd0ff9f1ec77c90001f4d48..a6904911a0791570eb1d177529c4a209f0cbce53 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-03-21  Rodney Dawes  <dobey@novell.com>
+
+       * gtk/gtk.symbols:
+       * gtk/gtkicontheme.[ch]:
+       * docs/reference/gtk/gtk-sections.txt:
+       * tests/testicontheme.c:
+       Add a new API call gtk_icon_theme_list_contexts so that one can
+       choose icons from a theme by context (#420719)
+       
 2007-03-21  Ross Burton  <ross@burtonini.com>
 
        * gtk/gtktexttag.c:
index 258df39efc344ace35aa44bb344743abe9f732ad..a6a57c89d12ac2837e3cee52e76a7dd87cbf0e2e 100644 (file)
@@ -6004,6 +6004,7 @@ gtk_icon_theme_set_custom_theme
 gtk_icon_theme_has_icon
 gtk_icon_theme_lookup_icon
 gtk_icon_theme_load_icon
+gtk_icon_theme_list_contexts
 gtk_icon_theme_list_icons
 gtk_icon_theme_get_icon_sizes
 gtk_icon_theme_get_example_icon_name
index f66898460aa552ad77024180b822a4ce0c5753f1..1e5c35bacd6cc5a24d870113ce9d7de7a1af84dc 100644 (file)
@@ -1764,6 +1764,7 @@ gtk_icon_theme_get_search_path_utf8
 #endif
 gtk_icon_theme_get_type G_GNUC_CONST
 gtk_icon_theme_has_icon
+gtk_icon_theme_list_contexts
 gtk_icon_theme_list_icons
 gtk_icon_theme_load_icon
 gtk_icon_theme_lookup_icon
index b981e228c2dbf9b2da15f4f21f7f0b31ae073419..9db5531c6906cd0f1e73f7e7430e07bf594c146a 100644 (file)
@@ -200,6 +200,8 @@ static GtkIconInfo *theme_lookup_icon (IconTheme        *theme,
 static void         theme_list_icons  (IconTheme        *theme,
                                       GHashTable       *icons,
                                       GQuark            context);
+static void         theme_list_contexts  (IconTheme        *theme,
+                                         GHashTable       *contexts);
 static void         theme_subdir_load (GtkIconTheme     *icon_theme,
                                       IconTheme        *theme,
                                       GKeyFile         *theme_file,
@@ -1648,6 +1650,51 @@ gtk_icon_theme_list_icons (GtkIconTheme *icon_theme,
   return list;
 }
 
+/**
+ * gtk_icon_theme_list_contexts:
+ * @icon_theme: a #GtkIconTheme
+ *
+ * Gets the list of contexts available within the current
+ * hierarchy of icon themes
+ *
+ * Return value: a #GList list holding the names of all the
+ *  contexts in the theme. You must first free each element
+ *  in the list with g_free(), then free the list itself
+ *  with g_list_free().
+ *
+ * Since: 2.12
+ **/
+GList *
+gtk_icon_theme_list_contexts (GtkIconTheme *icon_theme)
+{
+  GtkIconThemePrivate *priv;
+  GHashTable *contexts;
+  GList *list, *l;
+
+  priv = icon_theme->priv;
+  
+  ensure_valid_themes (icon_theme);
+
+  contexts = g_hash_table_new (g_str_hash, g_str_equal);
+
+  l = priv->themes;
+  while (l != NULL)
+    {
+      theme_list_contexts (l->data, contexts);
+      l = l->next;
+    }
+
+  list = NULL;
+
+  g_hash_table_foreach (contexts,
+                       add_key_to_list,
+                       &list);
+
+  g_hash_table_destroy (contexts);
+
+  return list;
+}
+
 /**
  * gtk_icon_theme_get_example_icon_name:
  * @icon_theme: a #GtkIconTheme
@@ -2109,6 +2156,25 @@ theme_list_icons (IconTheme  *theme,
     }
 }
 
+static void
+theme_list_contexts (IconTheme  *theme, 
+                    GHashTable *contexts)
+{
+  GList *l = theme->dirs;
+  IconThemeDir *dir;
+  const char *context;
+
+  while (l != NULL)
+    {
+      dir = l->data;
+
+      context = g_quark_to_string (dir->context);
+      g_hash_table_replace (contexts, context, NULL);
+
+      l = l->next;
+    }
+}
+
 static void
 load_icon_data (IconThemeDir *dir, const char *path, const char *name)
 {
index 1c607ad5809a1f23a408a3e49ab5c10505f05c90..8a0ae125ab4464d6fa3411b99d0c55293c33edac 100644 (file)
@@ -139,6 +139,7 @@ GdkPixbuf *   gtk_icon_theme_load_icon             (GtkIconTheme
 
 GList *       gtk_icon_theme_list_icons            (GtkIconTheme                *icon_theme,
                                                    const gchar                 *context);
+GList *       gtk_icon_theme_list_contexts         (GtkIconTheme                *icon_theme);
 char *        gtk_icon_theme_get_example_icon_name (GtkIconTheme                *icon_theme);
 
 gboolean      gtk_icon_theme_rescan_if_needed      (GtkIconTheme                *icon_theme);
index a5ded578dfd10ef07d50cdf9d60d74f26b69ccd2..c14f4d2d3214eb0f7ab7db128248e9eb926751b3 100644 (file)
@@ -31,6 +31,8 @@ usage (void)
           "usage: test-icon-theme list <theme name> [context]\n"
           " or\n"
           "usage: test-icon-theme display <theme name> <icon name> [size]\n"
+          " or\n"
+          "usage: test-icon-theme contexts <theme name>\n"
           );
 }
 
@@ -98,6 +100,16 @@ main (int argc, char *argv[])
       list = gtk_icon_theme_list_icons (icon_theme,
                                           context);
       
+      while (list)
+       {
+         g_print ("%s\n", (char *)list->data);
+         list = list->next;
+       }
+    }
+  else if (strcmp (argv[1], "contexts") == 0)
+    {
+      list = gtk_icon_theme_list_contexts (icon_theme);
+      
       while (list)
        {
          g_print ("%s\n", (char *)list->data);